/*
 * vim:et sts=4 sw=4 cindent:
 * $Id$
 */

import com.digg.services.API;
import com.digg.services.Request;
import com.digg.services.response.StoriesResponse;
import com.digg.fdk.model.Story;

API.appKey = 'http://diggflashdevkit.googlecode.com/svn/trunk/as2/examples/hellodigg';

// get the most recent story from the API
var response:StoriesResponse = API.getRecentStories(1, API.STORIES_POPULAR);
response.addLoadListener(onStoriesLoaded);

function onStoriesLoaded(event:Object):Void
{
    if (response.isLoaded())
    {
        var story:Story = response.getItem();
        field.text = story.title + " (" + story.diggs + " diggs)";
    }
    else
    {
        field.text = response.getError();
    }
}

// align the Stage to the top left, and prevent scaling
Stage.align = "TL";
Stage.scaleMode = "noScale";

// when the movie is resized, resize the text field accordingly
function onResize():Void
{
    this.field._width = Stage.width - this.field._x * 2;
    this.field._height = Stage.height - this.field._y * 2;
}

Stage.addListener(this);
